package com.web.user.member.utils;

import java.util.Timer;
import java.util.TimerTask;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.base.user.service.MemberService;
import com.web.user.member.ao.MemberAo;

@Component
@Scope("prototype")
public class LoginStatusThread extends Thread
{
	public  String flag = "online";
	private int count = 0;
	//private static MemberAo memberAo;
	private static MemberService memberService;
/*	private  HttpServletRequest request;
	private  HttpServletResponse response;*/
	private long memberId;
	private Timer timer; 
	
	LoginStatusThread()
	{
		
	}
	
	public LoginStatusThread(MemberAo memberAo,HttpServletRequest request,HttpServletResponse response,long memberId,MemberService memberService)
	{
		/*LoginStatusThread.memberAo = memberAo;
		this.request = request;
		this.response = response;*/
		this.memberId = memberId;
		LoginStatusThread. memberService =  memberService;
	}

	@Override
	public void run()
	{
		timer = new Timer ();
		timer.schedule (new TimerTask()
		{
			@Override
			public void run()
			{
				if(flag.equals ("not_online"))
				{
					count++;
					if(count>=10)
					{
						this.cancel ();
						try
						{
							LoginStatusThread.memberService.logOut (memberId);
							
						}catch (Exception e)
						{
							e.printStackTrace();
						}
						System.out.println ("ֹͣ");
					}
				}else 
				{
					count=0;
					flag = "not_online";
					System.out.println (flag);
				}
			}
		} ,1000 ,2000);
		
		System.out.println ("�߳�ֹͣ��");
	}
}
